<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\widgets\ActiveForm;
use kartik\widgets\DatePicker;

//use mdm\admin\components\AccessControl;
/* @var $this yii\web\View */
/* @var $searchModel ua_backend\models\search\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '用户管理';

$this->params['breadcrumbs'][] = $this->title;

?>

<div class="box">
    <div class="box-header with-border">

        <div class="action-btn col-sm-4 no-padding">
            <?php $form = ActiveForm::begin([
                'action' => ['download'],
                'method' => 'get',
                'id' => 'down-form',
                'options' => ['class' => 'form-horizontal'],
            ]); ?>
            <div class="flex">
                <?= DatePicker::widget([
                    'name' => 'UserSearch[date_start]',
                    'value' => date('Y-m-d', time()),
                    'type' => DatePicker::TYPE_RANGE,
                    'name2' => 'UserSearch[date_end]',
                    'value2' => date('Y-m-d', time()),
                    'language' => 'zh-CN',
                    'separator' => '~',
                    'options' => ['width' => '100%'],
                    'pluginOptions' => [
                        'autoclose'=>true,
                        'todayHighlight' => true,
                        'format' => 'yyyy-mm-dd',

                    ]
                ]); ?>

                <button class="btn btn-success" type="submit">
                    <i class="fa fa-download"></i>下载数据
                </button>

<!--                --><?php
//                $order = [
//                    'label'=> '<span class="label "><i class="fa fa-download"></i> 下载数据</span>',
//                    'url' => 'download?down=excel&'.$urlQuery,
//                    'options' => ['class'=>'btn btn-success']
//                ];
//
//                echo Html::a($order['label'],$order['url'],$order['options']);
                ?>
            </div>
            <?php ActiveForm::end(); ?>
        </div>

        <div class="search-box flex flex-end  col-sm-8 no-padding">
            <?php $form = ActiveForm::begin([
                            'action' => ['all'],
                            'method' => 'get',
                            'id' => 'search-form',
                            'options' => ['class' => 'form-horizontal'],
                        ]); ?>

                            <div class='input-group input-group-sm' style='width: 300px;margin-top:5px;'>
                            <?= $form->field($searchModel, 'skey',[
                                  'options'=>['class'=>'input-group input-group-sm','style'=>'width: 300px;'],
                                  'inputOptions' => ['placeholder' => Yii::t('app', 'Search Keyword'),'class' => 'form-control pull-right'],
                                    ])->label(false); ?>
                             <div class="input-group-btn">
                                <button class="btn btn-default" type="submit">
                                <i class="fa fa-search"></i>
                                </button>
                             </div>
                             </div>

            <?php ActiveForm::end(); ?>
        </div>    
    </div>    
    
<?php Pjax::begin(); ?> 

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'layout' => '<div class="box-body">{items}</div>
                         <div class="box-footer">
                            {summary}
                            <div class="_pager">{pager}</div>
                         </div>',
 
        'columns' => [
            'id' => [
                    'attribute' => 'id',
                    'enableSorting' => false,
                    'label' => 'UID',
                ],
            
                'avatar' => [
                    'attribute' => 'avatar',
                    'format' => ['image',['width'=>'40','height'=>'40']],
                    'label' => Yii::t('app', 'Avatar'),
                    'enableSorting' => false,
                ],

                'nickname' => [
                    'attribute' => 'nickname',
                    'label' => Yii::t('app', 'Nickname'),
                    'enableSorting' => false,
                    'value' => function ($model) {
                        return urldecode($model->nickname);
                    }
                ],

                'giftcode' => [
                    'attribute' => 'giftcode',
                    'label' => '游戏状态',
                    'enableSorting' => false,
                    'format' => 'html',
                    'value' => function ($model) {
                        $html = '/';
                        if ($model->giftcode>0) {
                            $html = '<span class="label label-success">已完成</span>';
                        } else {
                            $html = '<span class="label label-default">未完成</span>';
                        }
                        return $html;
                    }
                ],
                
                [
                    'attribute' => 'created_at',
                    'label' => Yii::t('app', 'Created at'),
                    'format' => ['date', 'php:Y-m-d'],
                    'enableSorting' => false,
                ],


//                [
//                    'attribute' => 'status',
//                    'enableSorting' => false,
//                    'label' => Yii::t('app', 'Status'),
//                    'format' => 'html',
////                    'visible'=>(Yii::$app->user->id === 1), //仅对某些用户展示
//                    'value' => function ($model) {
//                        $html = '/';
//                        if($model->status == 2){
//                            $html =  '<span class="label label-success">已核销</span>';
//                        }else{
//                            if($model->giftcode!=''){
//                                $html = '<span class="label label-danger">待核销</span>';
//                            }
//                        }
//                        return $html;
//                    }
//                ],


//                [
//                    'header' => Yii::t('app', 'Operations'),
//                    'class' => 'ua_backend\components\ActionColumn',
////                    'visible'=>(Yii::$app->user->id === 1),
//                    'template' => '{verify}',
//                    'buttons' => [
//                        'verify' => function($url, $model){
//                            if($model->giftcode!=''){
//                                if($model->status==1){
//                                    return Html::a('<span class="fs-16 fa fa-gift"></span><span
//            class="fs-13 pd-l-2">核销</span>', 'verify?id='.$model->id);
//                                }
//                            }
//                        },
//                    ]
//                ],
        ],
    ]); ?>
<?php Pjax::end(); ?>
</div>

<?php
//记录当前页面
$url = Yii::$app->request->getHostInfo().Yii::$app->request->url;
Yii::$app->user->setReturnUrl($url);
?>
